package com.longge;

public class ReverseOddLevels {


    public TreeNode reverseOddLevels(TreeNode root) {

        dfs(root.left, root.right, true);

        return root;
    }

    private void dfs(TreeNode left, TreeNode right, boolean reverse) {
        if (left==null||right==null) return;
        if (reverse) {
            int temp = left.val;
            left.val = right.val;
            right.val = temp;
        }
        dfs(left.left, right.right, !reverse);
        dfs(left.right, right.left, !reverse);
    }

}
